package database.example.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

import database.example.dao.EmployeeDao;
import database.example.dto.Employee;

public class EmployeeService extends AbsService<Employee>{
	ArrayList<Employee> list;
	
	public EmployeeService(Scanner sc, Connection connection) {
		super(sc, connection);
		dao = new EmployeeDao(connection);
	}

	
	@Override
	public Employee inputItemInfo(boolean b) {
		System.out.println("사원번호 사원명");
		Employee emp = new Employee(sc.nextInt(), sc.next());
		if(b){
			System.out.println("직책 상사 급여 부서번호");
			emp.setTitle(sc.next());			
			emp.setManager(sc.nextInt());			
			emp.setSalary(sc.nextInt());			
			emp.setDno(sc.nextInt());			
		}
		return emp;
	}
	
	@Override
	public void prnSubMenu() {
		System.out.println("1. 사원명 정렬 2. 직급별 정렬 3. 급여별 정렬 4. 부서별 정렬 5. 사원번호 정렬");
		
		try {
			list = dao.listItems();
			int res = sc.nextInt();

		switch (res) {
			case 1://	
				dao.prnItemList(new Comparator<Employee>() {

					@Override
					public int compare(Employee o1, Employee o2) {
						return o1.getEmpName().hashCode() - o2.getEmpName().hashCode();
					}
				});
				break;
			case 2://
				dao.prnItemList(new Comparator<Employee>() {
					
					@Override
					public int compare(Employee o1, Employee o2) {
						return o1.getTitle().hashCode() - o2.getTitle().hashCode();
					}
				});
				break;
			case 3://
				dao.prnItemList(new Comparator<Employee>() {
					
					@Override
					public int compare(Employee o1, Employee o2) {
						return o1.getSalary() - o2.getSalary();
					}
				});
				break;
			case 4://
				dao.prnItemList(new Comparator<Employee>() {
					
					@Override
					public int compare(Employee o1, Employee o2) {
						return o1.getDno() - o2.getDno();
					}
				});
				break;
			default://
				dao.prnItemList(null);
				
		}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
